<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>社区党员管理</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/plugins/bootstrap-table/css/bootstrap-table.css">
<link href="${pageContext.request.contextPath}/plugins/bootstrap-select/css/bootstrap-select.min.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/plugins/bootstrap-switch/css/bootstrap-switch.min.css">
</head>
<style>
</style>
<body style="padding-bottom: 90px; background-color: #ECF0F5;">
	<section class="content" style="margin: 15px; background-color: white;">
		<div class="row">
			<div class="col-sm-12">
				<table id="table">
					<thead style="background-color: #00C0EF">
						<tr style="background-color: #00C0EF">
							<th class="text-center" data-field=""></th>
							<th class="text-center" data-field="partyMemberName">姓名</th>
							<th class="text-center" data-field="gender">性别</th>
							<th class="text-center" data-field="idNumber">身份证号</th>
							<th class="text-center" data-field="unit">所属单位</th>
							<th class="text-center" data-field="id">操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</section>
	<!-- Large modal -->
	<div id="modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">用户编辑</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<label for="user_account" class="control-label">用户名:</label> <input type="text" class="form-control" id="party_membern_name" placeholder="必填" >
					</div>
					<div class="form-group">
						<label for="role_id" class="control-label">性别:</label> <select id="gender" class="form-control">
							<option value="男">男</option>
							<option value="女">女</option>
						</select>
					</div>
					<div class="form-group">
						<label for="user_name" class="control-label">身份证号:</label> <input type="text" class="form-control" id="idNumber" placeholder="必填">
					</div>
					<div class="form-group">
						<label class="control-label">所属单位：</label> <input type="text" class="form-control" id="unit">
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button id="submitBtn" type="button" class="btn btn-primary" onclick="submit();">提交</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-export.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/tableExport.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-toolbar.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-filter-control.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-select/js/bootstrap-select.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-select/js/i18n/defaults-zh_CN.min.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script>
	// 	var flag = true;
	var partyMemberId = "";
	var isChecked = true;

	var table_dataset = [ {
		field : 'id',
		checkbox : true,
	}, {
		field : 'partyMemberName',
		align : 'center',
	}, {
		field : 'gender',
		align : 'center',
	}, {
		field : 'idNumber',
		align : 'center',
	}, {
		field : 'unit',
		align : 'center',
	}, {
		align : 'center',
		width : 200,
		formatter : actionFormatter,
	} ];

	function actionFormatter(value, row, index) {
		return [ "<button class='btn btn-primary btn-xs glyphicon glyphicon-pencil' onclick='showModal(\"" + row.partyMemberId + "\");'>编辑</button>",
				"&nbsp;<button class='btn btn-danger btn-xs glyphicon glyphicon-trash' onclick='del(\"" + row.partyMemberId + "\")'>删除</button>", ].join('');
	}

	$('#table')
			.bootstrapTable(
					{
						url : "${pageContext.request.contextPath}/PartyMember/selectPartyMemberPage",
						idField : "id",
						columns : table_dataset,
						striped : true, //是否显示行间隔色
						pagination : true, //是否显示分页
						pageSize : 10, //每页的记录行数
						pageList : [ 10, 25, 50, 100 ], //可供选择的每页的行数
						search : false, //是否显示搜索
						showRefresh : true,
						sidePagination : "server", //表示服务端请求  
						queryParamsType : "limit",
						queryParams : function queryParams(params) { //设置查询参数  
							var param = {
								offset : params.offset,
								limit : params.limit,
								kod : $("#kod").val()
							};
							return param;
						},
						toolbar : "<button class='btn btn-primary glyphicon glyphicon-plus' onclick='showModal(\""
								+ ''
								+ "\");'>新增党员数据</button>"
								+ "<div class='input-group' style='width:250px;float:right;margin-top:2px;margin-left:20px;'><input type='text' class='form-control' placeholder='根据姓名、身份证号、单位' id='kod' name='kod'>"
								+ "<span class='input-group-btn'><button class='btn btn-default' type='button' onclick='Querry(\"" + '' + "\");'>查询</button></span></div>",
						icons : {
							paginationSwitchDown : 'glyphicon-collapse-down icon-chevron-down',
							paginationSwitchUp : 'glyphicon-collapse-up icon-chevron-up',
							refresh : 'glyphicon-refresh icon-refresh',
							toggle : 'glyphicon-list-alt icon-list-alt',
							columns : 'glyphicon-th icon-th',
							detailOpen : 'glyphicon-plus icon-plus',
							detailClose : 'glyphicon-minus icon-minus',
							"export" : 'glyphicon-export icon-share'
						},
						showExport : true,
						exportDataType : 'basic',
						exportTypes : [ 'json', 'xml', 'csv', 'txt', 'sql', 'excel' ]
					});

	// 	$(function() {
	// 		$.ajax({
	// 			url : "${pageContext.request.contextPath}/selectAllAppUser",
	// 			type : "get",
	// 			dataType : "json",
	// 			success : function(data) {
	// 				var list = data.list;
	// 				var user = "";
	// 				for (var i = 0; i < list.length; i++) {
	// 					user += "<option value='"+list[i].userId+"'>" + list[i].userName + "</option>";
	// 				}
	// 				$("#party_membern_name2").html(user);
	// 				$('.selectpicker').selectpicker('refresh');
	// 			}
	// 		});
	// 	});

	function showModal(id) {
		// 		$('#party_membern_name').selectpicker('deselectAll');
		// 		$('.selectpicker').selectpicker('val', '');
		if (id == "") {
			partyMemberId = '';
			$('#party_membern_name').val('');
			$('#gender').val('');
			$("#idNumber").val('');
			$('#unit').val('');
			$('#modal').modal({
				backdrop : 'static',
				keyboard : false
			});
		} else {
			partyMemberId = id;
			$.ajax({
				url : "${pageContext.request.contextPath}/PartyMember/selectById",
				type : "get",
				data : {
					partyMemberId : partyMemberId
				},
				dataType : "json",
				success : function(data) {
					var PartyMember = data.PartyMember;
					$('#party_membern_name').val(PartyMember.partyMemberName);
					// 					$('.selectpicker').selectpicker('val', PartyMember.partyMemberName);
					$('#gender').val(PartyMember.gender);
					$("#idNumber").val(PartyMember.idNumber);
					$('#unit').val(PartyMember.unit);
					$('#modal').modal({
						backdrop : 'static',
						keyboard : false
					});
				},
				error : function() {
					layer.msg('系统异常!', {
						icon : 2,
						time : 800
					});
				}
			});
		}
	}

	function submit() {
		$("#submitBtn").button('loading');
		var partyMemberName = $('#party_membern_name').val();
		var gender = $('#gender').val();
		var idNumber = $("#idNumber").val();
		var unit = $('#unit').val();
		var regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
		// 		if (flag) {
		// 			if (partyMemberName2 === null) {
		// 				layer.alert("请填写姓名!");
		// 				$("#submitBtn").button('reset');
		// 				return false;
		// 			}
		// 		} else {
		if (partyMemberName === '') {
			layer.alert("请填写姓名!");
			$("#submitBtn").button('reset');
			return false;
		}
		// 		}
		if (!regIdNo.test(idNumber)) {
			layer.alert('身份证号填写有误!');
			$("#submitBtn").button('reset');
			return false;
		}
		$.ajax({
			url : "${pageContext.request.contextPath}/PartyMember/insertAndUpdatePartyMember",
			type : "post",
			data : {
				partyMemberId : partyMemberId,
				partyMemberName : partyMemberName,
				gender : gender,
				idNumber : idNumber,
				unit : unit
			},
			dataType : "json",
			success : function(data) {
				var result = data['result'];
				if (result == "1") {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						$("#table").bootstrapTable('refresh');
						$("#modal").modal("hide");
					}, 1000);
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
				}
				$("#submitBtn").button('reset');
			},
			error : function() {
				layer.msg('系统繁忙，请稍后再试!', {
					icon : 2,
					time : 800
				});
				$("#submitBtn").button('reset');
			}
		});

		return false;
	}

	function del(id) {//删除数据
		layer.confirm("是否要删除数据?", function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/PartyMember/deleteMember",
				type : "post",
				data : {
					partyMemberId : id
				},
				dataType : "json",
				success : function(data) {
					if (data.result == "1") {
						layer.msg('操作成功!', {
							icon : 1,
							time : 800
						});
						setTimeout(function() {
							$("#table").bootstrapTable('refresh');
						}, 500);
					} else {
						layer.msg('操作失败!', {
							icon : 2,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});
		});
	}

	function Querry() {
		$("#table").bootstrapTable('refresh');
	}
</script>
</html>
